package genetic.operators;

import genetic.interfaces.Individual;
import genetic.interfaces.Mutation;

public class MutationFlip<I extends Individual<Integer,?>> implements Mutation<I>{

	//Randomiza o gene a ser pego
	public int RandGene(int suplimit, int inflimit){
		Integer gene;

		gene = (int) (inflimit + Math.random()*suplimit);
		return gene;
	}

	//Troca 2 genes aleatorios de lugar
	public void mutation(I individual) {
		Integer tmp;
		int index1, index2;

		//		System.out.println("Mutation Flip");


		index1 = RandGene(individual.getNumberOfGenes(), 0);
		do{
			index2 = RandGene(individual.getNumberOfGenes(), 0);
		}while(index1 != index2);

		tmp = individual.getGene(index1);

		individual.setGene(index1, individual.getGene(index2));
		individual.setGene(index2, tmp);
	}
}